class TMatrix {
  private int dimension;
  private int matrix[][];
  private TPoint corn;

  public TMatrix(int d) {
    this.dimension=d;
    this.matrix = new int [d][d];
    corn = new TPoint(0,0);
  }

  public TMatrix(TMatrix d) {
    this.dimension=d.getDimension();
    this.matrix = new int [this.dimension][this.dimension]; 
    for (int i = 0; i < this.dimension; i++){
      for (int j = 0; j < this.dimension; j++){
        this.matrix[i][j] = d.getMatrixValue(i,j);
      }
    }
    corn = new TPoint(0,0);
  }

  public int getDimension() {
    return this.dimension;
  }

  public void setDimension(int d) {
    this.dimension=d;
    this.matrix=new int[d][d];
  }

  public int[][] getMatrix() {
    return this.matrix;
  }

  public void setMatrix(int [][] m) {
    this.matrix=m;
  }

  public int getMatrixValue(int i, int j) {
    return this.matrix[i][j];
  }

  public void setMatrixValue(int i, int j, int value) {
    this.matrix[i][j]=value;
  }

  public void setCorn(TPoint corn1) {
    corn = corn1;
  }

  public TPoint getCorn() {
    return corn;
  }

  public void mPrint() {
    for (int i = 0 ; i < dimension ; i++) {

      for (int j = 0 ; j < dimension ; j++) {
        print(matrix[i][j] + " ");
        //print((i + corn.getX()) + " ; " + (j + corn.getY()) + "  ");
      }
      println();
    }
  }
  
  public void mPrint1() {
    for (int i = 0 ; i < dimension ; i++) {

      for (int j = 0 ; j < dimension ; j++) {
        //print(matrix[i][j] + " ");
        print((i + corn.getX()) + ";" + (j + corn.getY()) + "  ");
      }
      println();
    }
  }
  
  public Field getField() {
    Field f = new Field();
    for (int i = 0 ; i < dimension ; i++) {
      for (int j = 0 ; j < dimension ; j++) {
        f.setCellValue(i,j,matrix[i][j]);
      }
    }
    return f;
  }
  
  public void addition(TMatrix mat){
    for (int i = 0; i < this.dimension; i++){
      for (int j = 0; j < this.dimension; j++){
        this.matrix[i][j] = mat.getMatrixValue(i,j) + this.matrix[i][j];
      }
    } 
  }
  
  public int getMax(){
    int max = 0;
    for (int i = 0; i < this.dimension; i++){
      for (int j = 0; j < this.dimension; j++){
        if (matrix[i][j] > max){
          max = matrix[i][j];
        }
      }
    }
    return max;
    
  }
  
  public void getInverted(){
    TMatrix m = new TMatrix(this);
    for (int i = 0; i < this.dimension; i++){
      for (int j = 0; j < this.dimension; j++){
        this.matrix[i][j] = m.getMatrixValue(j,i);
      }
    }
  }

}
